<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<script type="text/javascript">
    /**
     * 自定义验证规则
     */
    function validateForm(){
        form.bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                imageInfo_1: {
                    validators: {
                        notEmpty: {message: "请上传图片"},
                        file:{maxSize: 1024*1024, message: '请上传一张最大不超过1M的jpg/png/gif图片文件'}
                    }
                },
                materialTitle: {
                    validators: {
                        notEmpty: {message: "素材图文标题不可为空"},
                        stringLength: {max: 100, message: "素材图文标题最大长度为100"}
                    }
                },
                picDescription: {
                    validators: {
                        notEmpty: {message: "图片正文描述不可为空"},
                        stringLength: {max: 1000, message: "图片正文描述最大长度为1000"}
                    }
                },
                clickSkipUrl: {
                    validators: {
                        notEmpty: {message: "点击链接跳转Url不可为空"},
                        stringLength: {max: 100, message: "图片正文描述最大长度为100"},
                        regexp: {
                            regexp: validateUtil.webUrl,
                            message: '请输入有效的网址'
                        }
                    }
                },
                picDigestDescription: {
                    validators: {
                        stringLength: {max: 240, message: "图片摘要描述最大长度为240"}
                    }
                },
                author: {
                    validators: {
                        stringLength: {max: 100, message: "作者最大长度为100"}
                    }
                },
                remark: {
                    validators: {
                        stringLength: {max: 500, message: "备注最大长度为500"}
                    }
                }
            }
        });
    }

    /**
     * 添加图文素材信息
     */
	<shiro:hasPermission name="back_gotoMaterialImageTxtPage_add">
    function addInfo(){
        $("#myModalLabel").empty().text("添加图文素材信息");
        $("#materialImageTxtInfoId").val("");
        $("#publicNumberId").val("");
        $("#createTime").val("");
        $("#imageTxtMediaId").val("");
        $("#infoSendFlag").val("");
        $("#modifier").val("");
        $("#lastUpdateDate").val("");
        $("#creater").val("");
        $("#deletedFlag").val("");
        $("#imageInfoTypeEnumId").val("");
        /**清空隐藏域的值**/
        resetAddForm();
        /**如果有上传图片功能添加此代码，否则可以去掉**/
        initImageForAdd(1,"sys_wx","image_material",1,50,50);
    }
	</shiro:hasPermission>

    /**
     * 编辑图文素材信息
     */
	<shiro:hasPermission name="back_gotoMaterialImageTxtPage_update">
    function editInfo(){
        $("#myModalLabel").empty().text("修改图文素材信息");
        /**获取选中行的id**/
        var selectedRow= $("#tt").bootstrapTable('getSelections');
        if(selectedRow.length==1){
            var id=selectedRow[0].materialImageTxtInfoId;
            $("#btn_edit").attr("data-target","#addOrEditModal");/**选中了记录后才可打开对应的模态框**/
            $.ajax({
                type: "POST",
                dataType: "JSON",
                url: "${basePath}/back/wx/material/imageTxt/getWxMaterialImageTxtInfoObject.sjson",
                data: {materialImageTxtInfoId:id},
                success: function(result){
                    var data = JSON.parse(result.data);
                    var wxMaterialImageTxtInfo = data.wxMaterialImageTxtInfo;
                    $("#imageUrl_1").val(wxMaterialImageTxtInfo.picUrl);
                    $("#materialImageTxtInfoId").val(wxMaterialImageTxtInfo.materialImageTxtInfoId);
                    $("#publicNumberId").val(wxMaterialImageTxtInfo.publicNumberId);
                    $("#imageInfoTypeEnumId").val(wxMaterialImageTxtInfo.imageInfoTypeEnumId);
                    $("#imageTxtMediaId").val(wxMaterialImageTxtInfo.imageTxtMediaId);
                    $("#materialTitle").val(wxMaterialImageTxtInfo.materialTitle);
                    $("#picDigestDescription").val(wxMaterialImageTxtInfo.picDigestDescription);
                    $("#picDescription").val(wxMaterialImageTxtInfo.picDescription);
                    $("#clickSkipUrl").val(wxMaterialImageTxtInfo.clickSkipUrl);
                    $("#author").val(wxMaterialImageTxtInfo.author);
                    $("#originalLink").val(wxMaterialImageTxtInfo.originalLink);
                    $("#infoSendFlag").val(wxMaterialImageTxtInfo.infoSendFlag);
                    $("#creater").val(wxMaterialImageTxtInfo.creater);
                    $("#createTime").val(new Date(wxMaterialImageTxtInfo.createTime).Format("yyyy-MM-dd hh:mm:ss"));
                    $("#modifier").val(wxMaterialImageTxtInfo.modifier);
                    $("#lastUpdateDate").val(new Date(wxMaterialImageTxtInfo.lastUpdateDate).Format("yyyy-MM-dd hh:mm:ss"));
                    $("#deletedFlag").val(wxMaterialImageTxtInfo.deletedFlag);
                    $("#remark").val(wxMaterialImageTxtInfo.remark);
                    /**回写预览上传文件所需的信息，如果有上传图片功能添加此代码，否则可以去掉**/
                    initImageForUpdate(1,"sys_wx","image_material",1,50,50,"${uploadPath}",wxMaterialImageTxtInfo.picUrl);
                    reValidateForm();
                    removeValidateField('imageInfo_1');
                }
            });
        }else{
            $("#btn_edit").attr("data-target", "");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }
	</shiro:hasPermission>
</script>

<!--添加编辑模态框（Modal） -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel"></h5>
			</div>
			<div class="modal-body">

				<form id="form1"  method="post" action="${basePath}/back/wx/material/imageTxt/saveOrUpdateWxMaterialImageTxtInfo.sjson">
					<input id="materialImageTxtInfoId" type="hidden" name="materialImageTxtInfoId"  value="" noclear="true"/>
					<input id="publicNumberId" type="hidden" name="publicNumberId" value="" />
					<input id="createTime" type="hidden" name="createTime" value="" />
					<input id="imageTxtMediaId" type="hidden" name="imageTxtMediaId" value=""  noclear="true"/>
					<input id="infoSendFlag" type="hidden" name="infoSendFlag" value="" />
					<input id="originalLink" type="hidden" name="originalLink" value="" />
					<input id="modifier" type="hidden" name="modifier" value="" />
					<input id="lastUpdateDate" type="hidden" name="lastUpdateDate" value="" />
					<input id="creater" type="hidden" name="creater" value="" />
					<input id="deletedFlag" type="hidden" name="deletedFlag" value="" />
					<input id="imageInfoTypeEnumId" type="hidden" name="imageInfoTypeEnumId" value="" />

					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>图片:</td>
							<td class="toleft_td">
								<div class="container">
									<input id="imageUrl_1" type="hidden" name="picUrl" value=""/>
									<div class="form-group" id="fileWrap1"></div>
								</div>
								<span style="color:red">提示：请上传规格宽60px，高60px的图片</span>
							</td>
						</tr>

						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>素材图文标题:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="materialTitle" name="materialTitle" placeholder="请输入素材图文标题"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">图片摘要描述:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="picDigestDescription" name="picDigestDescription" placeholder="请输入图片摘要描述"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>图片正文描述:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<textarea class="form-control input-sm" type="text" id="picDescription" name="picDescription" placeholder="请输入图片正文描述"></textarea>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>点击链接跳转Url:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="clickSkipUrl" name="clickSkipUrl" placeholder="请输入点击链接跳转Url，如：http://www.shopjsp.com"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">作者:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="author" name="author" placeholder="请输入作者"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">备注:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="remark" name="remark" placeholder="请输入备注"/>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary"  onclick="submitForm()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>

		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
